package br.uvv.sao.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name = "sao_palavra_chave")
public class PalavraChave implements Serializable {

	private static final long serialVersionUID = -5326882354326608266L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Version
	private Integer version = 0;

	@Column(name = "nome", nullable = false, length = 127)
	private String nome;

	@OneToMany(fetch = FetchType.LAZY, targetEntity = Questao.class, mappedBy="palavraChave")
	private List<Questao> questoes;
	
	@OneToMany(fetch = FetchType.LAZY, targetEntity = QuestaoBase.class, mappedBy="palavraChave")
	private List<QuestaoBase> questoesBase;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public List<Questao> getQuestoes() {
		return questoes;
	}

	public void setQuestoes(List<Questao> questoes) {
		this.questoes = questoes;
	}
	
	public List<QuestaoBase> getQuestoesBase() {
		return questoesBase;
	}
	
	public void setQuestoesBase(List<QuestaoBase> questoesBase) {
		this.questoesBase = questoesBase;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result
				+ ((questoes == null) ? 0 : questoes.hashCode());
		result = prime * result
				+ ((questoesBase == null) ? 0 : questoesBase.hashCode());
		result = prime * result + ((version == null) ? 0 : version.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PalavraChave other = (PalavraChave) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (questoes == null) {
			if (other.questoes != null)
				return false;
		} else if (!questoes.equals(other.questoes))
			return false;
		if (questoesBase == null) {
			if (other.questoesBase != null)
				return false;
		} else if (!questoesBase.equals(other.questoesBase))
			return false;
		if (version == null) {
			if (other.version != null)
				return false;
		} else if (!version.equals(other.version))
			return false;
		return true;
	}
}